#include <gtk/gtk.h>
#include "common.h"

int main( int argc, char *argv[]){
    GtkWidget *window;GtkWidget *table;
    GtkWidget *titleLabel;
    GtkWidget *activateButton;
    GtkWidget *titleHalign;
    GtkWidget *helpHAlign;
    GtkWidget *closeValign;
    GtkWidget *closeButton;
    GtkWidget *textView;
    GtkWidget *helpButton;
    GtkWidget *ok;

    gtk_init(&argc, &argv);

    /* window */
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_widget_set_size_request (window, 300, 250);         /*设置窗口大小*/
    gtk_window_set_resizable(GTK_WINDOW(window), FALSE);    /*设置窗口不能拉伸*/
    gtk_window_set_title(GTK_WINDOW(window), TITLE);

    gtk_container_set_border_width(GTK_CONTAINER(window), 15);  /*设置容器边界大小*/

    /* table */
    table = gtk_table_new(8, 4, FALSE);
    gtk_table_set_col_spacings(GTK_TABLE(table), 3);

    /* title label */
    titleLabel = gtk_label_new("Windows");
    titleHalign = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(titleHalign), titleLabel);
    gtk_table_attach(GTK_TABLE(table), titleHalign, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);

    /* textView */
    textView = gtk_text_view_new();
    gtk_text_view_set_editable(GTK_TEXT_VIEW(textView), FALSE);
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textView), FALSE);
    gtk_table_attach(GTK_TABLE(table), textView, 0, 2, 1, 3, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    /* activateButton */
    activateButton = gtk_button_new_with_label("Activate");
    gtk_widget_set_size_request(activateButton, 50, 30);
    gtk_table_attach(GTK_TABLE(table), activateButton, 3, 4, 1, 2, GTK_FILL, GTK_SHRINK, 1, 1);


    /* closeButton and closeVAlign */
    closeButton = gtk_button_new_with_label("Close");
    gtk_widget_set_size_request(closeButton, 70, 30);
    closeValign = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(closeValign), closeButton);
    gtk_table_set_row_spacing(GTK_TABLE(table), 1, 3);
    gtk_table_attach(GTK_TABLE(table), closeValign, 3, 4, 2, 3, GTK_FILL, GTK_FILL | GTK_EXPAND, 1, 1);

    /* helpButton and helpHAlign */
    helpHAlign = gtk_alignment_new(0, 1, 0, 0);
    helpButton = gtk_button_new_with_label("Help");
    gtk_container_add(GTK_CONTAINER(helpHAlign), helpButton);
    gtk_widget_set_size_request(helpButton, 70, 30);
    gtk_table_set_row_spacing(GTK_TABLE(table), 3, 6);
    gtk_table_attach(GTK_TABLE(table), helpHAlign, 0, 1, 4, 5, GTK_FILL, GTK_FILL, 0, 0);

    /* okButton */
    ok = gtk_button_new_with_label("OK");
    gtk_widget_set_size_request(ok, 70, 30);
    gtk_table_attach(GTK_TABLE(table), ok, 3, 4, 4, 5, GTK_FILL, GTK_FILL, 0, 0);
    gtk_container_add(GTK_CONTAINER(window), table);
    g_signal_connect_swapped(G_OBJECT(window), "destroy",G_CALLBACK(gtk_main_quit), G_OBJECT(window));

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}
